﻿/*
 * printf.h
 *
 *  Created on: 2016年6月23日
 *      Author: admin
 */

#pragma once
#ifndef PRINTF_H_
#define PRINTF_H_


#include <stdint.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C"
{
#endif
/****************************/



#if 1
	// 纯linux
	#define PCL_ADD()
	#define PCL_NONE				 "\e[0m"
	#define PCL_BLACK				 "\e[0;30m"
	#define PCL_L_BLACK 			 "\e[1;30m"
	#define PCL_RED 				 "\e[0;31m"
	#define PCL_L_RED				 "\e[1;31m"
	#define PCL_GREEN				 "\e[0;32m"
	#define PCL_L_GREEN 			 "\e[1;32m"
	#define PCL_BROWN				 "\e[0;33m"
	#define PCL_YELLOW				 "\e[1;33m"
	#define PCL_BLUE				 "\e[0;34m"
	#define PCL_L_BLUE				 "\e[1;34m"
	#define PCL_PURPLE				 "\e[0;35m"
	#define PCL_L_PURPLE			 "\e[1;35m"
	#define PCL_CYAN				 "\e[0;36m"
	#define PCL_L_CYAN				 "\e[1;36m"
	#define PCL_GRAY				 "\e[0;37m"
	#define PCL_WHITE				 "\e[1;37m"

	#define PCL_BOLD				 "\e[1m"
	#define PCL_UNDERLINE			 "\e[4m"
	#define PCL_BLINK				 "\e[5m"
	#define PCL_REVERSE 			 "\e[7m"
	#define PCL_HIDE				 "\e[8m"
	#define PCL_CLEAR				 "\e[2J"
	#define PCL_CLRLINE 			 "\r\e[K" //or "\e[1K\r"

	#define PCL_BG_BLACK			 "\e[0;40m"
	#define PCL_BG_L_BLACK			 "\e[1;40m"
	#define PCL_BG_RED				 "\e[0;41m"
	#define PCL_BG_L_RED			 "\e[1;41m"
	#define PCL_BG_GREEN			 "\e[0;42m"
	#define PCL_BG_L_GREEN			 "\e[1;42m"
	#define PCL_BG_BROWN			 "\e[0;43m"
	#define PCL_BG_YELLOW			 "\e[1;43m"
	#define PCL_BG_BLUE 			 "\e[0;44m"
	#define PCL_BG_L_BLUE			 "\e[1;44m"
	#define PCL_BG_PURPLE			 "\e[0;45m"
	#define PCL_BG_L_PURPLE 		 "\e[1;45m"
	#define PCL_BG_CYAN 			 "\e[0;46m"
	#define PCL_BG_L_CYAN			 "\e[1;46m"
	#define PCL_BG_GRAY 			 "\e[0;47m"
	#define PCL_BG_WHITE			 "\e[1;47m"

	#define CRLF					"\n"
#endif



// 调试信息(从dma.c移到printf.h,添加__FILE__, __LINE__信息，便于查找问题)
#define DMA_DBG_EN						1

#define DMA_DBG_UNKNOWN					0
#define DMA_DBG_DEFAULT					1
#define DMA_DBG_VERBOSE					2
#define DMA_DBG_DEBUG					3
#define DMA_DBG_INFO					4
#define DMA_DBG_WARN					5
#define DMA_DBG_ERROR					6
#define DMA_DBG_FATAL					7
#define DMA_DBG_SILENT					8

#ifndef DMA_DBG_LEVEL
#define DMA_DBG_LEVEL					DMA_DBG_DEBUG
#endif


#ifndef printfColor
//#define printfColor(color, ...)		printf(color __VA_ARGS__)
#define printfColor(color_, ...)	do{ printf(color_ __VA_ARGS__);  printf(PCL_NONE); }while(0)

#endif

#if DMA_DBG_LEVEL <= DMA_DBG_VERBOSE
#define dbg_verbose(...)				do{ printf("[%s,%d] ", __FILE__, __LINE__); printfColor(PCL_NONE, __VA_ARGS__); }while(0)
#define dbg_succ(...)					do{ printf("[%s,%d] ", __FILE__, __LINE__); printfColor(PCL_L_GREEN, __VA_ARGS__); }while(0)
#else
#define dbg_verbose(...)
#define dbg_succ(...)
#endif

#if DMA_DBG_LEVEL <= DMA_DBG_DEBUG
#define dbg_debug(...)					do{ printf("[debug,%s,%d] ", __FILE__, __LINE__); printfColor(PCL_NONE, __VA_ARGS__); }while(0)
#else
#define dbg_debug(...)
#endif

#if DMA_DBG_LEVEL <= DMA_DBG_INFO
#define dbg_info(...)					do{ printf("[info,%s,%d] ", __FILE__, __LINE__); printfColor(PCL_L_CYAN,	__VA_ARGS__); }while(0)
#else
#define dbg_info(...)
#endif

#if DMA_DBG_LEVEL <= DMA_DBG_WARN
#define dbg_warn(...)					do{ printf("[info,%s,%d] ", __FILE__, __LINE__); printfColor(PCL_YELLOW , __VA_ARGS__); }while(0)
#else
#define dbg_warn(...)
#endif

#if DMA_DBG_LEVEL <= DMA_DBG_ERROR
#define dbg_error(...)					do{ printf("[error,%s,%d] ", __FILE__, __LINE__); printfColor(PCL_L_RED,  __VA_ARGS__); }while(0)
#else
#define dbg_error(...)
#endif

#if DMA_DBG_LEVEL <= DMA_DBG_FATAL
#define dbg_fatal(...)					do{ printf("[fatal,%s,%d] ", __FILE__, __LINE__); printfColor(PCL_L_PURPLE, __VA_ARGS__); }while(0)
#else
#define dbg_fatal(...)
#endif

#if DMA_DBG_LEVEL <= DMA_DBG_SILENT
#define dbg_silent(...)					do{ printf("[%s,%d] ", __FILE__, __LINE__); printfColor(PCL_BG_L_RED, __VA_ARGS__); }while(0)
#else
#define dbg_silent(...)
#endif

/****************************/
#ifdef __cplusplus
}
#endif

#endif /* PRINTF_H_ */
